package com.hc.sss.hgw.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hc.sss.common.ResultMap;
import com.hc.sss.pojo.User;
import com.hc.sss.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserService userService;
	
	//会员登录
	@RequestMapping("/login")
	@ResponseBody
	public int login(User user,HttpServletRequest request){
		if(userService.login(user)!=null) {
			request.getSession().setAttribute("user", userService.login(user));
			return 1;
		}
		return 0;
	}
	
	//会员注册
	@RequestMapping("/addUser")
	@ResponseBody
	public int addUser(User user) {
		if(userService.addUser(user)==1) {
			return 1;
		}
		return 0;
	}
	
	
	@RequestMapping("/getusersession")
	@ResponseBody
	public User login(HttpServletRequest request){
		
		User user=(User) request.getSession().getAttribute("user");
		
		return userService.userFindByName(user);
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public int UpdateUser(User user,HttpServletRequest request){
		
		return userService.updateByPrimaryKeySelective(user);
	}
	
	//查询所有用户分页   llz  04/10 9:56
	@RequestMapping("/findUserList")
	@ResponseBody
	public ResultMap<User> findUserList(User user,Integer page,Integer limit) {
		Map<String, Object> paramMap = new HashMap<>();
		paramMap.put("page", page);
		paramMap.put("limit", limit);
		paramMap.put("user", user);
		ResultMap<User> resultMap = userService.findUserList(paramMap);
		return resultMap;
	}
	
	@RequestMapping("/deleteUser")
	@ResponseBody
	public int deleteUser(User user,HttpServletRequest request){
		user.setUserStatus(3);
		return userService.updateByPrimaryKeySelective(user);
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public List<User> UserList(){
		List<User> list = userService.selectUserAll();
		return list;
	}
	
}
